package com.atguigu.szdz.dcsyl.controller;

import com.atguigu.szdz.dcsyl.common.utils.R;
import com.atguigu.szdz.dcsyl.service.ZndbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/zndb")
public class ZndbController {
    @Autowired
    ZndbService zndbService;

    @RequestMapping("/getZndbList")
    public R getZndbList(@RequestBody Map<String, Object> params) {
        Integer currentPage = (Integer) params.get("currentPage");
        String keyword = (String) params.get("keyword");

        if ((keyword != "") && (keyword.length() > 0)) {
            keyword
                    = " where (well_name like '%" + keyword + "%') or (divide_tname like '%"
                    + keyword + "%') or (asname_tname like '%" + keyword + "%')";
        }
        System.out.println("aaaaaaaaaaaaaaaa:" + keyword);

        List<Map<String, Object>> zndbList = zndbService.getZndbList(currentPage, keyword);
        List<Map<String, Object>> contList = zndbService.getCount("select count(*) from dc_zndb" + keyword);
        Object count = contList.get(0).get("count");
        Long c = (Long) count;
        return R.ok().put("zndbList", zndbList).put("total", c);
    }

    @RequestMapping("/uploadFile")
    public R uploadFile(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return R.error("文件不能为空");
        }
        System.out.println("ffffffffffffffffffff:" + file.getName());
        return R.ok();
    }

}
